package xin.core.jpa.model;

import xin.core.jpa.JpaConstant;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.util.List;

@MappedSuperclass
@Cacheable
@Data
@ToString(callSuper=true)
@EqualsAndHashCode(callSuper = true, of = {})
public class SimpleTreeUUIDEntity<T> extends SimpleUUIDSortableEntity {

	@Column(length = JpaConstant.UidColumnLength)
	protected String parentId;

	@OneToMany(fetch = FetchType.LAZY)
	@OrderBy(JpaConstant.PriorityOrderAsc)
	@Cascade(CascadeType.ALL)
	@JoinColumn(name = "parentId")
	protected List<T> children;
}